/*
 * SafeShare.h
 *
 *  Created on: Feb 10, 2015
 *      Author: phong
 */

#ifndef SRC_SAFESHARE_H_
#define SRC_SAFESHARE_H_

class SafeShare {
public:
	int refCount;
	SafeShare() {refCount = 1;}

    SafeShare* share() { refCount++; return this; }

    static void free(SafeShare* obj) {
    	obj->refCount--;
    	if (obj->refCount == 0) delete obj;
    }

protected:
	virtual ~SafeShare() {}
};

#endif /* SRC_SAFESHARE_H_ */
